#include <cstdlib>
#include <iostream>
#include "adspaudio.h"

using namespace std;

int main(int argc, char *argv[])
{
    adspAudio x;
    adspAudio y;
    float vol;
    string filename;
    cout << "Input Filename for First Input: ";
    cin >> filename;
    filename = filename + ".wav";
    x.importFromWAV((char *) filename.c_str());
    if(!x.error())
    {
        cout << "Input Filename for Second Input: ";
        cin >> filename;
        filename = filename + ".wav";
        y.importFromWAV((char *) filename.c_str());
        if(!y.error())
        {
            cout << "Successfully Imported Both Audio.\n";
            if(x.getSampleRate() == y.getSampleRate())
            {
                cout << endl << "Please Choose Volume of First Input (1-100): ";
                cin >> vol;
                x.changeVolume(vol);
                cout << endl << "Please Choose Volume of Second Input (1-100): ";
                cin >> vol;
                cout << endl;
                y.changeVolume(vol);
      
                if(x.getDuration() <= y.getDuration())
                {
                    y.mixAudio(x.getData(), y.getData(), x.getDuration(), y.getDuration(), x.getNumChannels(), y.getNumChannels());
                }
                else
                {
                    x.mixAudio(y.getData(), x.getData(), y.getDuration(), x.getDuration(), y.getNumChannels(), x.getNumChannels());
                }
            
                cout << "Input Filename for Export: ";
                cin.clear(); //clear the error bits for the cin input stream
                cin.sync();
                cin >> filename;
                filename = filename + ".wav";
                if(x.getDuration() <= y.getDuration())
                {
                    y.exportToWAV(filename);
                }
                else
                {
                    x.exportToWAV(filename);
                }
            }
            else
            {
                cout << "The Files do not Have the Same Sampling Rate." << endl;
            }
        }
    }
    cout << "Press the Enter Key to Continue ...";
    cin.get();
    return EXIT_SUCCESS;
}
